import uuid
from Connector.client import res_success, res_err
from service.func.fx_run import fx_run


class CmdFxRun:
    name = "cmd_fx_run"
    id = uuid.uuid4()

    def __init__(self, service, Params, Tag, Type):
        self.service = service
        self.params = Params
        self.tag = Tag
        self.type = Type

    async def execute(self):
        script: str = self.params.get("code", None)
        if script is None:
            await res_err(self.tag, self.type, "script is required")
        else:
            result = fx_run(self.service, script)
            await res_success(self.tag, self.type, {"result": result})
